package cn.cuilan.service;

import cn.cuilan.entity.BookClassify;
import cn.cuilan.repository.BookClassifyRepository;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 书籍分类
 *
 * @author zhang.yue
 */
@Service
public class BookClasifyService {

    private final BookClassifyRepository bookClassifyRepository;

    @Autowired
    public BookClasifyService(BookClassifyRepository bookClassifyRepository) {
        this.bookClassifyRepository = bookClassifyRepository;
    }

    public BookClassify findById(long id) {
        return bookClassifyRepository.findOne(id);
    }

    public List<BookClassify> finAllBookClassify(String classifyName) {
        if (StringUtils.isNotBlank(classifyName)) {
            return bookClassifyRepository.findByClassifyNameLike("%" + classifyName + "%");
        }
        return (List<BookClassify>)bookClassifyRepository.findAll();
    }
}
